import sys
import os
import time
from sys import argv
sys.path.append("..")


from redisoper import CRedis

class ImgCmd:
    def __init__(self):
        self.redis_key = 'bd_spider:start_urls';
        self.r = CRedis()
        self.filepath="/data/scrdata/bdimgs/";


    def addredis(self,key):
           #scrapyItem = self.r.lindex(self.fruitlistkey, i)
            keyword = key.split(",")[0];
            filename=key.split(",")[1];
            path =self.filepath+ filename;
            if os.path.exists(path):
                return;
            for j in range(20):
                url = "https://image.baidu.com/search/flip?tn=baiduimage&ie=utf-8&word=" + keyword + "&pn=" + str(
                    j * 20) + "&gsm=78&filename="+filename
                self.r.lpush(self.redis_key, url)

len=len(sys.argv);
if(len>2):
        icmd=ImgCmd();
        key=argv[1]
        icmd.addredis(key)


#my=ImgCmd();
#while True:
   # my.addredis();
    #time.sleep(1000)